<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>22-随机生成字符串</title>
	</head>
	<body>
		<script type="text/javascript">
			/**
			 * @param {需要的字符串长度} len
			 * @return str字符串
			 */
			function getRandStr(len){
				var len = len||32;
				//需要一个种子
				var seed = 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890';
				//空的字符串
				var str = '';
				//循环拼接
				for(var i=0;i<len;i++){
					str+= seed.charAt(Math.floor(Math.random()*seed.length));
				}
				return str;
			}
			
			var x = getRandStr(8);
			console.log(x);
		</script>
	</body>
</html>
